home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1999 July
/
Macworld (1999-07).dmg
/
Shareware World
/
Info
/
For Developers
/
Mops 3.4.sea
/
Mops source
/
Asm Source
/
parser
< prev
next >
Wrap
Text File
|
1996-11-17
|
6KB
|
177 lines
\ ---- FILE: parser ---------------- \
\ Sep 96 BDA Use asembler to rewrite ParseToken.
0 -> dlevel
0 value POS \ position on line
0 value LINECT
0 value STOREDTOKEN
0 value CHARCOUNT \ char in definition
string TOKEN
\ New Charclass
\ We now return 0 for digits and 1 for letters.
code CHARCLASS \ :code CHARCLASS \ New September 1,1996 BA-
hex \ loc
0C00 w, 0020 w, \ CMPI.B #$20,D0 ; ' ' Blank
6F5C w, \ BLE.S cntrl
0C00 w, 0041 w, \ CMPI.B #$41,D0 ; 'A'
6D16 w, \ BLT.S trydig
0C00 w, 005A w, \ CMPI.B #$5A,D0 ; 'Z'
6F5E w, \ BLE.S maybe
0C00 w, 0061 w, \ CMPI.B #$61,D0 ; 'a'
6D16 w, \ BLT.S tryspec
0C00 w, 007A w, \ CMPI.B #$7A,D0 ; 'z'
6F52 w, \ BLE.S maybe ;
7002 w, \ MOVEQ #$02,D0 ; special Everything above 'z'
4E75 w, \ RTS
0C00 w, 0030 w, \ trydig CMPI.B #$30,D0 ; '0'
6D06 w, \ BLT.S tryspec
0C00 w, 0039 w, \ CMPI.B #$39,D0 ; '9'
6F3E w, \ BLE.S digit
0C00 w, 0028 w, \ tryspec CMPI.B #$28,D0 ; '('
6732 w, \ BEQ.S letter
0C00 w, 0029 w, \ CMPI.B #$29,D0 ; ')'
672C w, \ BEQ.S letter
0C00 w, 0024 w, \ CMPI.B #$24,D0 ; '$'
672A w, \ BEQ.S dollar
0C00 w, 002D w, \ CMPI.B #$2D,D0 ; '-'
6710 w, \ BEQ.S minus
0C00 w, 003B w, \ CMPI.B #$3B,D0 ; ';'
671A w, \ BEQ.S letter
0C00 w, 002B w, \ CMPI.B #$2B,D0 ; '+'
671A w, \ BEQ.S digit
7002 w, \ MOVEQ #$02,D0 ; special
4E75 w, \ RTS
1210 w, \ minus MOVE.B (A0),D1 ; Look at next char
0C01 w, 0028 w, \ CMPI.B #$28,D1 ; '(' -( If we're in a word,
6708 w, \ BEQ.S letter ; it's a spec,
2004 w, \ MOVE.L D4,D0 ; otherwise a digit.
4E75 w, \ RTS
7003 w, \ cntrl MOVEQ #$03,D0
4E75 w, \ RTS
7001 w, \ letter MOVEQ #$01,D0
4E75 w, \ RTS
7400 w, \ dollar MOVEQ #$00,D2 ; Change Aa..Zz to digit in case
7000 w, \ digit MOVEQ #$00,D0 ; BASE >10
4E75 w, \ RTS
2002 w, \ maybe MOVE.L D2,D0
4E75 w, \ ;code
decimal
code PARSETOKEN \ :code PARSETOKEN \ New September 1,1996 BA- Requires the
\ New charclass to function
hex \ loc
2C1E w, \ POP D6
6724 w, \ BEQ.S eol
5346 w, \ SUBQ.W #$1,D6
7401 w, \ MOVEQ #$01,D2 ; Set maybe to return letter
2056 w, \ MOVEA.L (A6),A0 ; DUP POP A0
7800 w, \ MOVEQ #$00,D4 ; Initially '-' is to be a digit
7A20 w, \ MOVEQ #$20,D5 ; ' ' Setup bloop
1018 w, \ bloop MOVE.B (A0)+,D0 ; Skip blanks
B005 w, \ CMP.B D5,D0
52CE w, FFFA w, \ DBHI D6,bloop
6F10 w, \ BLE.S eol
2248 w, \ MOVEA.L A0,A1 ; Test the first char.
6100 w, FF5E w, \ BSR dic[charclass]
671E w, \ BEQ.S number
5340 w, \ SUBQ.W #$1,D0
672C w, \ BEQ.S word
7803 w, \ MOVEQ #$03,D4 ; special
6042 w, \ BRA.S kleanup
4296 w, \ eol CLR.L (A6) ; DROP PUSH #0
2D3C w, 0 w, 4 w, \ PUSH #4
2D3C w, 0 w, 0 w, \ PUSH #0
2D3C w, 0 w, 0 w, \ PUSH #0
4E75 w, \ RTS
7801 w, \ number MOVEQ #$01,D4 ; set '-' to be a digit
5346 w, \ SUBQ.W #$1,D6
6B24 w, \ BMI.S end
1018 w, \ numloop MOVE.B (A0)+,D0
6100 w, FF32 w, \ BSR dic[charclass]
56CE w, FFF8 w, \ DBNE D6,numloop
6012 w, \ BRA.S endtst
7802 w, \ word MOVEQ #$02,D4 ; set '-' to be a special
5346 w, \ SUBQ.W #$1,D6
6B12 w, \ BMI.S end
1018 w, \ wdloop MOVE.B (A0)+,D0
6100 w, FF20 w, \ BSR dic[charclass]
5300 w, \ SUBQ.B #$01,D0
52CE w, FFF6 w, \ DBHI D6,wdloop
4A46 w, \ endtst TST.W D6 ; <-Need this to get the
6B02 w, \ BMI.S end ; string length right
5388 w, \ SUBQ.L #$1,A0
5246 w, \ end ADDQ.W #$1,D6
2C86 w, \ kleanup MOVE.L D6,(A6) ; DROP PUSH D6
2D04 w, \ PUSH D4
5389 w, \ SUBQ.L #$1,A1
2209 w, \ MOVE.L A1,D1
2D09 w, \ PUSH A1
91C1 w, \ SUBA.L D1,A0
2D08 w, \ PUSH A0
4E75 w, \ ;code
decimal
false value LABEL_THERE? \ Set true if this line has a token at the
\ start - i.e. a label. Used by main loop.
: GETLINE { \ #chars ch -- }
msg" getLine called"
(Frefill) 0= ?error 154 \ Premature end of file
bytesRead: topFile ++> charCount \ May be different to #TIB @
#tib @ -> #chars
0 -> pos
1 ++> linect
#chars
IF
tib c@ -> ch
ch bl =
IF false
ELSE ch & ; =
IF false
ELSE ch & \ = IF false ELSE true THEN
THEN
THEN
ELSE
false
THEN
-> label_there? ;
: RestOfLine \ ( -- addr len )
tib pos + #tib @ pos - ;
\ NEXTTOKEN puts the token into string Token and returns one of the following
\ four token types:
\ number, word, special, end-of-line
: NEXTTOKEN { \ aa bb cc dd ee -- tokenType }
\ Note: the locals are dummies to force regs to be saved over the
\ ParseToken call!!
clear: token
storedToken
NIF
restOfLine parseToken put: token
dup eol =
IF
2drop eol
ELSE
swap ( # chars left ) #tib @ over - -> pos
NIF eol -> storedToken THEN
THEN
ELSE
storedToken
0 -> storedToken
THEN
uc: token 2drop ;
endload